package org.neuedu.ssmp.crm.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.additional.query.impl.LambdaQueryChainWrapper;
import org.neuedu.ssmp.crm.entity.Relationship;
import org.neuedu.ssmp.crm.entity.vo.ResponseEntity;
import org.neuedu.ssmp.crm.mapper.RelationshipMapper;
import org.neuedu.ssmp.crm.service.IRelationshipService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author MoonHolder
 * @since 2019-12-09
 */
@Service
public class RelationshipServiceImpl extends ServiceImpl<RelationshipMapper, Relationship> implements IRelationshipService {

    @Override
    public ResponseEntity add(Relationship relationship) {
        if (baseMapper.insert(relationship) != 0){
            return ResponseEntity.ok("新建交往记录成功！");
        }
        return ResponseEntity.error("新建失败！");
    }

    @Override
    public ResponseEntity del(int id) {
        if (baseMapper.deleteById(id) != 0){
            return ResponseEntity.ok("删除交往记录成功！");
        }
        return ResponseEntity.error("删除交往记录失败！");
    }

    @Override
    public ResponseEntity edit(Relationship relationship) {
        if (baseMapper.updateById(relationship) != 0){
            return ResponseEntity.ok("修改交往记录成功！");
        }
        return ResponseEntity.error("修改交往记录失败！");
    }

    @Override
    public IPage<Relationship> relationshipPage(int pageIndex, int pageSize, int customerId) {
        return new LambdaQueryChainWrapper<>(baseMapper).eq(Relationship::getCustomerId,customerId).page(new Page<>(pageIndex,pageSize));
    }
}
